﻿using TestingConcurrencyBenchmark.Helpers;

namespace TestingConcurrencyBenchmark.Problems.DiningPhilosophers.Philosophers
{
    internal class EvenNumberMultiplexPhilosopher : AbstractPhilosopher
    {
        private readonly BenchmarkSemaphore _evenNumberMultiplex;

        public EvenNumberMultiplexPhilosopher(BenchmarkSemaphore leftFork, BenchmarkSemaphore rightFork, BenchmarkSemaphore evenNumberMultiplex) : base(leftFork, rightFork)
        {
            _evenNumberMultiplex = evenNumberMultiplex;
        }

        public override void GetForks()
        {
            _evenNumberMultiplex.WaitOne();
            RightFork.WaitOne();
            LeftFork.WaitOne();
        }

        public override void PutForks()
        {
            RightFork.Release();
            LeftFork.Release();
            _evenNumberMultiplex.Release();
        }
    }
}